<?php
namespace app\admin\controller;

use think\Controller;
use think\Db;

class Index extends Controller
{
    //登录方法
    public function login()
    {
        return  $this->fetch('index/login');
    }

    //判断登录来的账号密码是否与数据库一致???
    public function logininfo()
    {

        $data['username'] = input('post.username');
        $data['password'] = input('post.password');
        //dump($data);
        $list = Db::table('admin')->where('adminname',$data['username'])
                                  ->where('pwd',$data['password'])
                                  ->select();
        // dump($list);
        if(!empty($list)){
            return view('index/index',[
                'title' => '后台主页',
            ]);
        } else {
            return view('index/login',[
                'title' => '后台主页',
            ]);
        }
    }

    //用户管理首页
    public function people()
    {
        $list = Db::table('user')->select();
        //dump($list);
        return view('index/elements',[
            'title' => '用户管理首页',
            'list' => $list,
        ]);

    }
    //返回后台首页方法
    public function shouye(){
        return $this->fetch('index/index');
    }


    //判断状态
    public function status(){
        $a = ($_GET['status'])==1?'2':'1';
        // return $a;
        $id = $_GET['id'];
        //return $id;

        $status = Db::table('user')
                  ->where('id',$id)
                  ->update(['status' => $a]);
        // dump($status);
        $list = Db::table('user')->select();
        //dump($list);
        return view('index/elements',[
            'title' => '用户管理首页',
            'list' => $list,
        ]);



    }




}